/**
 * 
 */
package optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.selection;

import optimization.naturalOptimization.evolutionaryAlgorithm.EvolutionaryAlgorithm;
import optimization.naturalOptimization.population.individual.Individual;

/**
 * This class provides the comma selection in evolutionary algorithms.
 * @author Kevin Wagner
 * @version 1.0
 */
public class CommaSelector extends Selector {

	/**
	 * Creates a new comma selector.
	 * @param parentEA
	 */
	public CommaSelector(EvolutionaryAlgorithm parentEA) {
		super(parentEA);
	}

	/* (non-Javadoc)
	 * @see optimization.naturalOptimization.evolutionaryAlgorithm.evolutionaryOperator.EvolutionaryOperator#work()
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public void work() {
		Individual[] ind = new Individual[getParentEA().getLambda()];
		                  		for (int i = 0; i < getParentEA().getLambda(); i++) {
		                  			ind[i] = getParentEA().getProgenyPopulation().getIndividual(i);
		                  			
		                  		}
		                  		sortIndividuals(ind);
		                  		getParentEA().getParentPopulation().removeAllIndividuals();
		                  		for (int i = 0; i < getParentEA().getMu(); i++) {
		                  			ind[i].setParentPopulation(getParentEA().getParentPopulation());
		                  			getParentEA().getParentPopulation().addIndividual(ind[i]);

		                  		}
		                  		getParentEA().getProgenyPopulation().removeAllIndividuals();

	}

}
